//package com.ag.answergames.service.wallet.impl;
//
//import com.ag.answergames.entity.AdultAccountEntity;
//import com.ag.answergames.mapper.wallet.AdultBalanceMapper;
//import com.ag.answergames.service.wallet.AdultBalanceService;
//import com.ag.answergames.service.wallet.ChildBalanceService;
//import com.ag.answergames.service.wallet.PersonalDetailService;
//import com.ag.answergames.util.SnowflakeIdWorkerController;
//import com.ag.answergames.vo.common.Result;
//import com.baomidou.mybatisplus.core.conditions.Wrapper;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.awt.image.BufferedImage;
//
///**
// * @author: aoaowu
// * @program: answer-game
// * @description: 大人账户余额service层的impl
// * @create: 2023/04/19 09:05
// **/
//@Service
//public class AdultBalanceServiceImpl implements AdultBalanceService {
//    @Autowired
//    private AdultBalanceMapper adultBalanceMapper;
//
//    @Autowired
//    private PersonalDetailService personalDetailService;
//
//    @Autowired
//    private ChildBalanceService childBalanceService;
//    @Autowired
//    private SnowflakeIdWorkerController snowflakeIdWorkerController;
//
//
//    @Override
//    public Result find(String openId) {
//        QueryWrapper<AdultAccountEntity> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("open_id", openId);
//        AdultAccountEntity adultAccountEntity = adultBalanceMapper.selectOne(queryWrapper);
//        if (adultAccountEntity != null && adultAccountEntity.getBalance() != null) {
//            return Result.success(adultAccountEntity.getBalance());
//        } else {
//            return Result.failed("余额显示出错");
//        }
//    }
//
//    @Override
//    public Result decrease(Long money, String openId) {
//        Result result = find(openId);
//        Long oldBalance = (Long) result.getData();
//        Long newBalance = oldBalance - money;
//        if (newBalance >= 0) {
//            AdultAccountEntity adultAccountEntity = new AdultAccountEntity();
//            adultAccountEntity.setBalance(newBalance);
//            UpdateWrapper<AdultAccountEntity> updateWrapper = new UpdateWrapper<>();
//            updateWrapper.eq("open_id", openId);
//            int update = adultBalanceMapper.update(adultAccountEntity, updateWrapper);
//            return Result.success(update);
//        }else {
//            return Result.failed("家长账户余额不足");
//        }
//    }
//
//    @Override
//    public Result topUp(Long money, String openId) {
//        Result result = find(openId);
//        Long oldBalance = (Long) result.getData();
//        Long newBalance = oldBalance + money;
//        AdultAccountEntity adultAccountEntity = new AdultAccountEntity();
//        adultAccountEntity.setBalance(newBalance);
//        UpdateWrapper<AdultAccountEntity> updateWrapper = new UpdateWrapper<>();
//        updateWrapper.eq("open_id", openId);
//        int update = adultBalanceMapper.update(adultAccountEntity, updateWrapper);
//        return Result.success(update);
//    }
//
//
//}
